/*
import axios from 'axios'
import Vue from 'vue'
*/

axios.defaults.baseURL='http://localhost:8081'
Vue.prototype.$http = axios;

/**
 * url字符串转对象
 * @param url
 * @returns {{}}
 */
function str2Obj(url){  //
    let paramStr = url.split("?")[1];
    if(paramStr){
        let paramArray = paramStr.split("&");
        let paramObj = {};
        //循环
        $.each(paramArray,function (index,param){
            let paramName = param.split("=")[0];
            let paramValue = param.split("=")[1];
            paramObj[paramName] = paramValue;
        })
        return paramObj;
    }
}

//前端登录拦截
let excludePath = ["/index.html","/back.html","/bind.html","/exam.html"];
let isRun = false;  // 是否放行  true 放行 false 拦截
let url = location.href;    // http://127.0.0.1:80/index.html
for(let i = 0;i<excludePath.length;i++){
    let path = excludePath[i];  // 字符串1.indexOf(字符串2)  找出字符串2在字符串1的索引位置
    if(url.indexOf(path) > -1){
        isRun = true;
        break;
    }
}
if(url === "http://127.0.0.1:80/" || url === "http://wx.rongcarservice.com/" || url === "http://localhost:80/"){
    isRun = true;
}
if(!isRun){ // isRun = false 说明要拦截
    let loginInfo = localStorage.getItem("loginInfo");
    if(!loginInfo){ // loginInfo == true  说明loginInfo是有值的  loginInfo==false 说明是没有值
        alert("请登录后再访问!");
        location.href = "/exam.html";  // 这个地方以后根据需求可以跳转到登录页面,现在就先跳转到首页
    }
}





